package com.hubu.core;
import com.hubu.json.Command;

import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Map;
public class Process {
    private Map<String,Handler> handleMap=null;



    public Result process(Database database, Command command){
        if(handleMap==null){
            initHandlerMap();
        }
        Handler handler = handleMap.get(command.getCommandType());
        Map.Entry<String,String> entry=new AbstractMap.SimpleEntry<>(command.getKey(),command.getValue());
        Result result = handler.handle(database, command.getKey(),entry);
        return result;
    }
    private void initHandlerMap() {
        handleMap=new HashMap<>();
        handleMap.put("put",new PutHandler());
        handleMap.put("get",new GetHandler());
    }
}
